package com.cloud.consumer.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import com.cloud.consumer.model.User;

@Service
public class UserService {

	@Autowired
	private RestTemplate restTemplate;

	/*
	 * @HystrixCollapser(batchMethod = "findAll", collapserProperties = {
	 * 
	 * @HystrixProperty(name = "timerDelayInMilliseconds", value = "100") })
	 */
	public Map<String, Object> find() {
		Map<String, Object> map=new HashMap<>();
		User user = restTemplate.getForEntity("http://user-service/user?id={1}", User.class, "312").getBody();
		map.put("user", user);
		return map;
	}

	@SuppressWarnings("unchecked")
	public List<User> findAll(String[] ids) {
		return restTemplate.getForObject("http://user-service/users?ids={1}", List.class,
				StringUtils.join(ids));
	}

}
